// pages/home/pages/company/company.js
import {
	input,
	datepicker,
	picker
} from '../../../../utils/tools'
const {
	http
} = require('../../../../utils/apiutils.js');
import {
	formatTime
} from '../../../../utils/util'
let miny = [];
let maxy = [];
for (let i = 16; i < 65; i++) {
	miny.push({
		name: i
	})
	maxy.push({
		name: i
	})
}
const nations = [
	'维吾尔族',
	'彝族',
	'藏族',
	'回族',
	'汉族',
	'满族',
	'蒙古族',
	'苗族',
	'壮族',
	'布依族',
	'侗族',
	'瑶族',
	'白族',
	'土家族',
	'哈尼族',
	'哈萨克族',
	'傣族',
	'黎族',
	'傈僳族',
	'佤族',
	'畲族',
	'高山族',
	'拉祜族',
	'水族',
	'东乡族',
	'纳西族',
	'景颇族',
	'柯尔克孜族',
	'土族',
	'达斡尔族',
	'仫佬族',
	'羌族',
	'布朗族',
	'撒拉族',
	'毛南族',
	'仡佬族',
	'锡伯族',
	'阿昌族',
	'普米族',
	'朝鲜族',
	'塔吉克族',
	'怒族',
	'乌孜别克族',
	'俄罗斯族',
	'鄂温克族',
	'德昂族',
	'保安族',
	'裕固族',
	'京族',
	'塔塔尔族',
	'独龙族',
	'鄂伦春族',
	'赫哲族',
	'门巴族',
	'珞巴族',
	'基诺族',
]
const tattoo = [
	'不限制',
	'不接收',
	'无攻击性纹身',
	'不能超过身份证大小',
	'穿短袖看不到',
	'小臂无纹身',
	'男生脱上衣检查',
]
let tattoos = []
tattoo.map(item => {
	tattoos.push({
		name: item
	})
})
const education = ['不限制', '小学', '初中', '高中/中专', '大专', '专科', '本科及以上', '26英文字母']
let educations = []
education.map(item => {
	educations.push({
		name: item
	})
})
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		filter(type, options) {
			if (type === 'minute') {
				return options.filter(option => option == "00");
			}
			return options;
		},
		img: [],
		type: '1',
		video: [],
		gw: '',
		currentDate: new Date().getTime(),
		clickPickerKey: '',
		pickershow: false,
		payType: ['小时', '天'],
		sex: ['男', '女', '不限'],
		ageArr: ['15-25', '25-35', '35-45', '45-55', '55-65'],
		weekArr: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
		peopleArr: [],
		peopleNum: 0,
		fileListVideo: [],
		loading: false,
		addrList: [],
		copefactoryJob: {},
		checked: 1,
		isPay: false, // 是否已经支付过了
		wxPayInfo: {},
		inputFocus: 'none',
		gwinput: '',
		workTime: '', // 工作时间
		workTime1:'',
		fy: '', // 费用合计 
		detePopup: false,
		ageDate: [14, 19],
		addJobBackId: '', // 添加岗位后返回的岗位id
		allWork: [],
		timeshow: false,
		minbonus: 0,
		currentTime: new Date().getHours() + ':00',
		active: 0,
		step: 1,
		top: 0,
		checkb: true,
		factoryJob: {
			images: [],
			type: '1', // 1 短期  2长期
			postType: '1', // 1兼职  2全职
			name: "",
			description: "",
			basicSalary: "",
			payType: "",
			isPlay: 1, //  1平台结算  2非平台结算
			registerTime: "",
			asOfTime: "",
			startTime: "",
			startDate: '',
			leaveDate: '',
			leaveTime: "",
			sex: "不限",
			education: "不限",
			age: '',
			dayofweek: [],
			floatSalary: 10,
			nations: [],
			tattoo: '不限',
			requirements: '',
			minAge: 18,
			maxAge: 45,
			workerPlace: '',
			lat: '',
			lng: ''
		},
		showSelect: false,
		inputcolor: '#e7e7e7e',
		range: [{
			name: '小时'
		},
		{
			name: '天'
		},
		{
			name: '月'
		},
		],
		miny,
		maxy,
		sex: [{
			name: '男'
		},
		{
			name: '女'
		},
		{
			name: '不限'
		},
		],
		nations,
		copyfactoryJobNations: [],
		nationsshow: false, // 控制民族弹窗
		tattoos, // 纹身数组
		educations, // 文化程度
		fileListImg: [],
		toast: false,
		img: [],
		floatSalaryData: {},
		minFloat: '', // 最小招聘费用
		minFloat1: '',
		factoryJobCopy: {}, // 复制 factoryJob 内容
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		// 如果不是修改执行 
		if (options.postType) {
			let payType = '';
			let pageTitle = ""
			if (options.postType == 1) {
				if (options.payType.indexOf('时') > -1) {
					payType = '小时';
					pageTitle = "兼职-时单"
				}
				if (options.payType.indexOf('日') > -1) {
					payType = '天'
					pageTitle = "兼职-日单"
				}
				if (options.payType.indexOf('次') > -1) {
					payType = '次'
					pageTitle = "兼职-次单"
				}
			} else {
				pageTitle = "全职"
				payType = options.payType
			}
			wx.setNavigationBarTitle({
				title: pageTitle
			})
			this.setData({
				['factoryJob.postType']: options.postType,
				['factoryJob.payType']: payType ? payType : '月',
				['factoryJob.isPlay']: options.postType == 2 ? 2 : 1
			})
		}
		this.getDataList();
		// // 正式需放开
		this.getgw();
		let copy = JSON.parse(JSON.stringify(this.data.factoryJob));
		this.setData({
			copefactoryJob: copy,
		})
		this.setData({
			["factoryJob.contactPerson"]: getApp().globalData.factoryInfo.contactName,
			["factoryJob.contactPhone"]: getApp().globalData.factoryInfo.factoryPhone
		})
		this.setLastData()
		this.getFloatSalary()
		if (getApp().globalData.playStatus == 2 || getApp().globalData.playStatus == 3) {
			this.newSetData()
		} else { 
			let data = wx.getStorageSync('lastData1');
		let _this = this;
		if (data) {
			wx.showModal({
				title: '提示',
				content: '需要继续编辑上次未发布的岗位么？',
				confirmText: '编辑',
				cancelText: '取消',
				success(res) {
					if (res.confirm) {
						let params = Object.assign({}, data)
						delete params.id;
						delete params.payType;
						delete params.postType;
						params = Object.assign({}, _this.data.factoryJob, params)
						_this.setData({
							factoryJob: params
						})
					}
				}
			})
		};
		}
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {
		let _this = this;
		const query = wx.createSelectorQuery()
		query.select('.h80').boundingClientRect(res => {
			_this.setData({
				top: `calc(${res.top}px + 82rpx)`
			})
		}).exec()

		if (!_this.data.factoryJob.workerPlace) {
			if (_this.data.addrList.length > 0) {
				_this.setData({
					['factoryJob.workerPlace']: _this.data.addrList[0].address,
					['factoryJob.lat']: _this.data.addrList[0].lat,
					['factoryJob.lng']: _this.data.addrList[0].lng,
				})
			}
		}

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {
		this.sbwy()
	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {
		this.sbwy()
	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},
	input: function name(event) {
		input.bind(this, event)();
		if (event.currentTarget.dataset.key == "factoryJob.basicSalary" && this.data.factoryJob.payType == '次') {
			this.setData({
				['factoryJob.floatSalary']: parseInt(event.detail.value * (this.data.minFloat / 100))
			})
		}
		// this.setData({
		//   showSelect:false
		// })
	},
	clickSelect() {
		this.setData({
			showSelect: true
		})
	},
	closeSelect() {
		this.setData({
			showSelect: false
		})
	},
	clickl(event) {
		this.setData({
			['factoryJob.name']: event.currentTarget.dataset.key
		})
		wx.nextTick(() => {
			this.closeSelect()
		})
		console.log(this.data.factoryJob.name)
	},
	pickerClick(e) {
		datepicker.bind(this, e)()
		let key = e.currentTarget.dataset.key;
		// 需同步设置报名时间
		if (key == "factoryJob.startDate") {
			this.setData({
				['factoryJob.registerTime']: formatTime(new Date(e.detail.value).getTime() - 60 * 60 * 1000 * 24)
			})
		}
		if (key == "factoryJob.leaveDate") {
			this.setData({
				['factoryJob.asOfTime']: formatTime(new Date(e.detail.value).getTime() - 60 * 60 * 1000 * 24)
			})
		}
	},
	pickerClick1(e) {
		picker.bind(this, e)()
		if (e.currentTarget.dataset.key == "factoryJob.payType") {
			this.setFloat();
		}
	},
	mzc(e) {
		// 民族选中取消
		let key = e.currentTarget.dataset.key;
		let arr = [...this.data.copyfactoryJobNations];
		if (arr.includes(key)) {
			arr.splice(arr.indexOf(key), 1)
		} else {
			arr.push(key)
		}
		this.setData({
			copyfactoryJobNations: arr
		})
	},
	shownations() {
		this.setData({
			nationsshow: true,
			copyfactoryJobNations: this.data.factoryJob.nations
		})
	},
	closenation() {
		this.setData({
			nationsshow: false
		})
	},
	copyFnation() {
		this.setData({
			nationsshow: false,
			['factoryJob.nations']: this.data.copyfactoryJobNations
		})
	},

	onClose() {
		this.setData({
			timeshow: false
		})
	},
	onChange(event) {
		this.setData({
			['factoryJob.postType']: event.detail,
		});
	},
	deletaImg: function (e) {
		//  console.log("-----",e);
		let index = e.detail.index;
		this.data.fileListImg.splice(index, 1);
		this.setData({
			fileListImg: this.data.fileListImg,
		})
	},
	tabClick(event) {
		let key = event.currentTarget.dataset.key;
		let val = event.currentTarget.dataset.val;
		this.setData({
			['factoryJob.' + [key]]: val,
			inputFocus: 'none',
			gwinput: ''
		})
	},
	tabClick1(event) {
		let key = event.currentTarget.dataset.key;
		let val = event.currentTarget.dataset.val;
		let arr = JSON.parse(JSON.stringify(this.data.factoryJob.dayofweek));
		if (arr.includes(val)) {
			arr.splice(arr.indexOf(val), 1);
		} else {
			arr.push(val)
		}
		this.setData({
			['factoryJob.dayofweek']: arr
		})
	},
	datePickerClick(event) {
		let key = event.currentTarget.dataset.key;
		this.setData({
			clickPickerKey: key,
			pickershow: true
		})
	},
	confirm(event) {
		let val = event.detail;
		let key = this.data.clickPickerKey;
		console.log(new Date(val))
		let data = new Date(val)
		console.log(formatTime(data))
		this.setData({
			['factoryJob.' + [key]]: formatTime(val),
			pickershow: false
		})
	},
	confirm1(event) {
		let val = event.detail;
		let key = this.data.clickPickerKey;
		this.setData({
			['factoryJob.' + [key]]: val,
			pickershow: false
		})
	},
	onClose() {
		this.setData({
			pickershow: false
		})
	},
	onclcickShowAddress(event) {
		let key = event.currentTarget.dataset.key;
		if (key == 'add') {
			wx.navigateTo({
				url: '/pages/me/pages/address/address?type=add',
				success: (result) => { },
				fail: (res) => { },
				complete: (res) => { },
			})
			return;
		}
		wx.navigateTo({
			url: '/pages/me/pages/address/address?type=1',
			success: (result) => { },
			fail: (res) => { },
			complete: (res) => { },
		})
	},
	getgw() {
		wx.showLoading({
			mask: true
		})
		// 获取可选岗位
		console.log(http)
		http.getAllJob({}, (res) => {
			wx.hideLoading()
			if (res.code == 0) {
				this.setData({
					allWork: res.data
				})
			} else {
				wx.showToast({
					title: res.message,
					icon: "none",
				})
			}
		}, (err) => {
			wx.hideLoading()
		})
	},
	verify() {
		let params = JSON.parse(JSON.stringify(this.data.factoryJob));
		if (this.loading) return;
		this.data.loading = true;
		if (params.payType != '小时') {
			if (!params.startDate || !params.leaveDate) {
				wx.showToast({
					title: '日期不能为空',
					icon: "none"
				})
				this.data.loading = false;
				return false;
			}
		}
		if ((params.payType == '小时' && params.postType == 1)) {
			if (!params.startTime || !params.leaveTime) {
				wx.showToast({
					title: '时单时间不能为空',
					icon: "none"
				})
				this.data.loading = false;
				return false;
			}
			if (new Date(params.startTime).getTime() >= new Date(params.leaveTime).getTime()) {
				wx.showToast({
					title: '开始日期时间需小于结束日期时间',
					icon: "none"
				})
				this.data.loading = false;
				return false;
			}
		}
		if (!params.basicSalary) {
			wx.showToast({
				title: '薪酬金额不正确',
				icon: "none"
			})
			this.data.loading = false;
			return false;
		}
		// if (params.payType=='天'&&params.basicSalary<31) {
		//   wx.showToast({
		//     title: '全职薪酬不能低于30',
		//     icon: "none"
		//   })
		//   this.data.loading = false;
		//   return false;
		// }
		// if (params.payType=='小时'&&params.basicSalary<4) {
		//   wx.showToast({
		//     title: '兼职薪酬不能低于3',
		//     icon: "none"
		//   })
		//   this.data.loading = false;
		//   return false;
		// }
		if (params.number < 1) {
			wx.showToast({
				title: '人数不能为空',
				icon: "none"
			})
			this.data.loading = false;
			return false;
		}
		if (!params.minAge) {
			wx.showToast({
				title: '最小年龄不能为空',
				icon: "none"
			})
			this.data.loading = false;
			return false;
		}
		if (!params.maxAge) {
			wx.showToast({
				title: '最大年龄不能为空',
				icon: "none"
			})
			this.data.loading = false;
			return false;
		}
		if (!params.workerPlace) {
			wx.showToast({
				title: '工作地址不能为空',
				icon: "none"
			})
			this.data.loading = false;
			return false;
		}
		if (!params.contactPerson || !params.contactPhone) {
			wx.showToast({
				title: '联系人不能为空',
				icon: "none"
			})
			this.data.loading = false;
			return false;
		}


		if (this.data.factoryJob.postType == 2) {
			if (!(this.data.fileListImg.length > 0)) {
				wx.showToast({
					title: '请上传一张封面图',
					icon: "none"
				})
				this.data.loading = false;
				return false;
			}

		}


		let workTime = 0;
		let workTime1 = 0;

		if (params.payType.indexOf('时') > -1) {
			params.payType = '小时'
		}
		if (params.payType.indexOf('日') > -1) {
			params.payType = '天'
		}
		if (params.postType == 2) {
			params.registerTime = params.registerTime + ' 08:00:00'
			params.asOfTime = params.asOfTime + ' 18:00:00';
			workTime = 1
			params.startTime = params.startDate + " 08:00:00";
			params.leaveTime = params.leaveDate + " 18:00:00";
			workTime1 = params.startTime+'--'+params.leaveTime;
		}
		if (params.postType == 1 && params.payType == '次') {
			params.registerTime = params.registerTime + ' ' + params.startTime + ":00"
			params.asOfTime = params.asOfTime + ' ' + params.leaveTime + ":00"
			params.registerTime = params.registerTime + ' ' + params.startTime + ":00"
			params.startTime = params.startDate + ' ' + params.startTime + ":00";
			params.leaveTime = params.leaveDate + ' ' + params.leaveTime + ":00";
			workTime = 1;
			workTime1 = params.startTime+'--'+params.leaveTime;
		}
		if (params.postType == 1 && params.payType == '时') {
			workTime = (params.leaveTime[0] + params.leaveTime[1]) - (params.startTime[0] + params.startTime[1]);
			params.registerTime = params.registerTime + ' ' + params.startTime + ":00"
			params.asOfTime = params.asOfTime + ' ' + params.leaveTime + ":00"
			params.startTime = params.startDate + ' ' + params.startTime + ":00";
			params.leaveTime = params.startTime + ' ' + params.leaveTime + ":00";
			workTime1 = params.startTime+'--'+params.leaveTime;

		}
		if (params.postType == 1 && params.payType == '小时') {
			workTime = (params.leaveTime[0] + params.leaveTime[1]) - (params.startTime[0] + params.startTime[1]);
			params.registerTime = params.registerTime + ' ' + params.startTime + ":00"
			params.asOfTime = params.asOfTime + ' ' + params.leaveTime + ":00"
			params.startTime = params.startDate + ' ' + params.startTime + ":00";
			params.leaveTime = params.startTime + ' ' + params.leaveTime + ":00";
			workTime1 = params.startTime+'--'+params.leaveTime;

		}
		if (params.postType == 1 && params.payType == '日') {
			workTime = ((new Date(params.leaveDate).getTime() - new Date(params.startDate).getTime()) / 3600 / 1000 / 24) * 1 + 1
			params.registerTime = params.registerTime + ' 00:00:00'
			params.asOfTime = params.asOfTime + ' 23:59:00'
			params.startTime = params.startDate + " 00:00:00";
			params.leaveTime = params.leaveDate + " 23:59:00";
			workTime1 = params.startTime+'--'+params.leaveTime;
		}
		if (params.postType == 1 && params.payType == '天') {
			workTime = ((new Date(params.leaveDate).getTime() - new Date(params.startDate).getTime()) / 3600 / 1000 / 24) * 1 + 1
			params.registerTime = params.registerTime + ' 00:00:00'
			params.asOfTime = params.asOfTime + ' 23:59:00'
			params.startTime = params.startDate + " 00:00:00";
			params.leaveTime = params.leaveDate + " 23:59:00";
			workTime1 = params.startTime+'--'+params.leaveTime;
		}
		let fy = 0;
		fy = workTime * params.basicSalary * params.number
		fy = fy + params.floatSalary * params.number * workTime;
		if (params.isPlay == 2) {
			fy = params.floatSalary * params.number * workTime;
		}
		
		this.setData({
			toast: true,
			workTime: workTime + params.payType,
			workTime1,
			fy: fy
		})

	},
	pay(res, fn) {
		wx.requestPayment({
			nonceStr: res.nonceStr,
			package: res.package,
			paySign: res.paySign,
			signType: res.signType,
			timeStamp: res.timeStamp,
			success(res) {
				fn()
			},
			fail(err) {
				wx.showToast({
					title: '支付失败',
					icon: 'none'
				})
			}
		})
	},
	dingyue() {
		// getApp().globalData.dingyue(this.verify);

		this.verify();

	},
	submit() {
		// wx.showLoading({
		//   mask: true
		// })
		let params = JSON.parse(JSON.stringify(this.data.factoryJob));
		if (params.payType.indexOf('时') > -1) {
			params.payType = '小时'
		}
		if (params.payType.indexOf('日') > -1) {
			params.payType = '天'
		}
		if (params.postType == 2) {
			params.registerTime = params.registerTime + ' 08:00:00'
			params.asOfTime = params.asOfTime + ' 18:00:00'
			params.startTime = params.startDate + " 08:00:00";
			params.leaveTime = params.leaveDate + " 18:00:00";
		}
		if (params.postType == 1 && params.payType == '次') {
			params.registerTime = params.registerTime + ' ' + params.startTime + ":00"
			params.asOfTime = params.asOfTime + ' ' + params.leaveTime + ":00"
			params.startTime = params.startDate + ' ' + params.startTime + ":00";
			params.leaveTime = params.leaveDate + ' ' + params.leaveTime + ":00";
		}
		if (params.postType == 1 && params.payType == '时') {
			params.registerTime = params.registerTime + ' ' + params.startTime + ":00"
			params.asOfTime = params.asOfTime + ' ' + params.leaveTime + ":00"
			params.leaveTime = params.startDate + ' ' + params.leaveTime + ":00";
			params.startTime = params.startDate + ' ' + params.startTime + ":00";
		}
		if (params.postType == 1 && params.payType == '小时') {
			params.registerTime = params.registerTime + ' ' + params.startTime + ":00"
			params.asOfTime = params.asOfTime + ' ' + params.leaveTime + ":00"
			params.leaveTime = params.startDate + ' ' + params.leaveTime + ":00";
			params.startTime = params.startDate + ' ' + params.startTime + ":00";
		}
		if (params.postType == 1 && params.payType == '日') {
			params.registerTime = params.registerTime + ' 00:10:00'
			params.asOfTime = params.asOfTime + ' 23:59:00'
			params.startTime = params.startDate + " 00:10:00";
			params.leaveTime = params.leaveDate + " 23:59:00";

		}
		if (params.postType == 1 && params.payType == '天') {
			params.registerTime = params.registerTime + ' 00:10:00'
			params.asOfTime = params.asOfTime + ' 23:59:00'
			params.startTime = params.startDate + " 00:10:00";
			params.leaveTime = params.leaveDate + " 23:59:00";

		}
		// params.registerTime = params.registerTime+' 08:00:00'
		// params.asOfTime = params.asOfTime+' 18:00:00'
		params.basicSalary = Number(params.basicSalary).toFixed(2) * 100;
		params.fixedSalary = Number(params.fixedSalary).toFixed(2) * 100;
		// if (params.postType == 2) {
		params.floatSalary = Number(params.floatSalary).toFixed(2) * 100;
		// }
		if (this.data.factoryJob.nations.length > 0) {
			params.nations = this.data.factoryJob.nations.join(',');
		} else {
			params.nations = ""
		}
		var _this = this;
		if (params.payType.indexOf('时') > -1) {
			params.payType = '小时'
		}
		if (params.payType.indexOf('日') > -1) {
			params.payType = '天'
		}
		getApp().globalData.playStatus == 3 && delete params.id;
		if (params.id) {
			http.updatePost(params,
				function (res) {
					wx.hideLoading()
					if (res.success) {
						wx.showModal({
							title: "提示",
							content: "修改岗位信息成功",
							showCancel: false,
							success: function () {
								try {
									_this.saveLastSubmit(params)
									getApp().globalData.workInfo = {}
									getApp().globalData.playStatus = 0
									// _this.data.factoryJobCopy = this.data.factoryJob
									_this.setData({
										factoryJob: {},
									})
									wx.navigateBack({
										delta: 1,
									});
								} catch (error) {
									console.log(error)
								}
							},
						})
					} else {
						wx.showToast({
							title: res.message,
							icon: "none",
						})
					}
				},
				function (err) {
					wx.hideLoading()
				})
		} else {
			console.log("--保存信息--")
			wx.showLoading({
				title: '加载中...',
				mask: true
			})
			http.addfactoryJob(params,
				function (res) {
					wx.hideLoading()
					if (res.success) {
						wx.showModal({
							title: "提示",
							content: "创建岗位成功,请耐心等待合作公司发布",
							showCancel: false,
							success: function () {
								_this.saveLastSubmit(params)
								_this.setData({
									factoryJob: {}
								})
								getApp().globalData.workInfo = {}
								getApp().globalData.playStatus = 0
								wx.reLaunch({
									url: '/pages/tabBar/home/index',
								})
							},
						})
						// _this.createWxPay(res.data.data.id,res.data.data.total);
						_this.setData({
							addJobBackId: res.data.id
						})
						// factoryId
					} else {
						wx.showToast({
							title: res.message,
							icon: "none",
						})
					}
				},
				function (err) {
					wx.hideLoading()
				})

		}
		wx.hideLoading({})
	},
	afterRead(event) {
		const {
			file
		} = event.detail;
		if (file.size > 5000000) {
			// 限制文件 5M以内
			wx.showToast({
				title: '文件过大，请重新选择',
				icon: "none"
			})
			return
		}
		if (file.type == "image") {
			file.isNew = true;
			this.setData({
				fileListImg: [...this.data.fileListImg, file],
			})
		} else {
			wx.showToast({
				title: '请上传图片文件',
			})
		}
	},
	check(event) {
		let key = event.currentTarget.dataset.key;
		let detail = event.detail;
		if (this.data.factoryJob.postType == 1) {
			detail = detail ? 1 : 2
		} else {
			detail = detail ? 2 : 1
		}
		switch (key) {
			case 'isPlay':
				this.setData({
					['factoryJob.isPlay']: detail
				})
				break;
			case 'checkb':
				this.setData({
					checkb: !this.data.checkb
				})
				break;
		}
	},
	upDataFile(data, index, type) {
		let item = data[index];
		console.log("-----", item);
		var that = this;
		var p = {
			url: item.url,
			name: "file",
			formData: {},
			isNew: item.isNew
		}
		wx.showLoading({
			mask: true
		})
		http.upDataFile(p,
			function (res) {
				console.log()
				console.log("---上传图片-", res);
				wx.hideLoading({
					success: (res) => { },
				})
				if (res.code == 0) {
					if (type == 1) {
						that.data.img.push(res.data);
						if (index == data.length - 1) {
							that.data.factoryJob.images = that.data.img;
							if (that.data.fileListVideo.length > 0) {
								that.upDataFile(that.data.fileListVideo, 0, 2);
								that.data.loading = false;
							} else {
								that.submit()
								that.data.loading = false;
							}
						} else {
							console.log("--继续执行--", index, data.length - 1);
							that.upDataFile(data, index + 1, type)
						}
					} else if (type == 2) {
						that.data.video.push(res.data);
						if (index == data.length - 1) {
							that.data.factoryJob.video = that.data.video;
							that.submit()
							that.data.loading = false;
						} else {
							that.upDataFile(data, index + 1, type)
							that.data.loading = false;
						}
					}
				} else {
					wx.showToast({
						title: res.message,
						icon: "nene",
					})
					that.data.loading = false;
				}


			},
			function (err) {
				wx.hideLoading()

				wx.showToast({
					title: err,
					icon: 'none',
					success() {
						that.data.loading = false;
					}
				})
			})
	},
	reset() {
		this.setData({
			factoryJob: Object.assign({}, this.data.copefactoryJob),
			images: [],

			fileListImg: [],
			fileListVideo: []
		})
	},
	btnclick(event) {
		// 招聘费用 加减按钮 事件
		let key = event.currentTarget.dataset.key;
		let val = this.data.factoryJob.floatSalary;
		if (key == 1) {
			val = val + 1
		} else {
			val = val > 10 ? (val - 1) : val
		}
		this.setData({
			['factoryJob.floatSalary']: val
		})
	},
	getDataList: function () {
		// 获取地址列表
		var that = this;
		http.getAddressList({},
			function (res) {
				wx.hideLoading()
				// console.log("-----已完成任务列表---", res);
				if (res.success) {
					that.setData({
						addrList: res.data.records
					})
				} else {
					wx.showToast({
						title: res.message,
						icon: "none",
					})
				}
			},
			function (err) {
				wx.hideLoading()
			})
	},
	addrpicker(event) {
		// 地址选择 赋值
		let index = event.detail.value;
		let indexDate = this.data.addrList[index];
		this.setData({
			"factoryJob.workerPlace": indexDate.address + (indexDate.remark != null ? indexDate.remark : ''),
			"factoryJob.lat": indexDate.lat,
			"factoryJob.lng": indexDate.lng,
		})
	},
	createWxPay(id, money) {
		http.createOrder(`${id}/${money}`, res => {
			wx.requestPayment({
				nonceStr: res.nonceStr,
				package: res.package,
				paySign: res.paySign,
				signType: res.signType,
				timeStamp: res.timeStamp,
				success(res) {
					// 支付成功才发送消息通知

					wx.showModal({
						title: "提示",
						content: "创建岗位成功,请耐心等待合作公司发布",
						showCancel: false,
						success: function () {
							wx.reLaunch({
								url: '../../../index/index',
							})
							// wx.navigateBack({
							//   delta: 1,
							// })
						},

					})
					try {
						http.subMsgforCreatePost(this.data.addJobBackId, function (res1) { }, function (res1) {
							console.log(res1)
						});
					} catch (error) {
						console.log(error)
					}
				},
				fail(err) {
					wx.showToast({
						title: '支付失败',
						icon: 'none'
					})
				}
			})
		}, err => {
			wx.showToast({
				title: err,
				icon: "none"
			})
		})
	},
	onclickSure() {
		if (this.data.fileListImg.length > 0) {
			this.upDataFile(this.data.fileListImg, 0, 1);
			return false;
		}else{
			this.submit()
		}
	},
	hidetoast() {
		this.setData({
			toast: false
		})
	},
	dateClose() {
		this.setData({
			detePopup: false
		})
	},
	showDate() {
		this.setData({
			detePopup: true
		})
	},
	dateRight() {
		if (this.data.ageDate[1] > this.data.ageDate[0]) {
			this.setData({
				['factoryJob.age']: this.data.miny[this.data.ageDate[0]] + '-' + this.data.maxy[this.data.ageDate[1]]
			})
		}
		this.dateClose()
	},
	bindChange(e) {
		this.setData({
			ageDate: e.detail.value
		})
	},
	addStep() {
		if (this.data.factoryJob.postType == 1) {
			if (!this.data.factoryJob.name || !this.data.factoryJob.description) {
				wx.showToast({
					title: '标题、描述不能为空',
					icon: 'none'
				})
				return
			}
			// 次单
			if (this.data.factoryJob.payType == '次') {
				if (!this.data.factoryJob.startDate || !this.data.factoryJob.leaveDate || !this.data.factoryJob.startTime || !this.data.factoryJob.leaveTime) {
					wx.showToast({
						title: '工作时间不能为空',
						icon: 'none'
					})
					return
				}
			}
			// 时单
			if (this.data.factoryJob.payType == '时' || this.data.factoryJob.payType == '小时') {
				if (!this.data.factoryJob.startDate || !this.data.factoryJob.startTime || !this.data.factoryJob.leaveTime) {
					wx.showToast({
						title: '工作时间不能为空',
						icon: 'none'
					})
					return
				}
			}
			// 日单
			if (this.data.factoryJob.payType == '日' || this.data.factoryJob.payType == '天') {
				if (!this.data.factoryJob.startDate || !this.data.factoryJob.leaveDate) {
					wx.showToast({
						title: '工作时间不能为空',
						icon: 'none'
					})
					return
				}
			}
			if (!this.data.factoryJob.basicSalary || !this.data.factoryJob.floatSalary || !this.data.factoryJob.number) {
				wx.showToast({
					title: '岗位工资、招聘费用及人数不能为0',
					icon: 'none'
				})
				return
			}
			if (!this.data.factoryJob.contactPerson || !this.data.factoryJob.contactPhone || !this.data.factoryJob.workerPlace) {
				wx.showToast({
					title: '联系人、电话及地址不能为空',
					icon: 'none'
				})
				return
			}
		}
		if (this.data.minFloat && this.data.minFloat1) {
			if (this.data.factoryJob.floatSalary * 100 < this.data.minFloat1) {
				wx.showToast({
					title: '招聘费用不能低于最低值' + this.data.minFloat1 / 100,
					icon: "none"
				})
				return
			}
		}
		// 判断 工作开始时间需大于  结束时间
		debugger
		if (this.data.factoryJob.payType == '次') { 
			let start = this.data.factoryJob.startDate+' ' + this.data.factoryJob.startTime;
			let end = this.data.factoryJob.leaveDate + ' ' + this.data.factoryJob.leaveTime;
			start =start.replace(/-/g, '/')
			end =end.replace(/-/g, '/')
			if (new Date(start).getTime() > new Date(end).getTime()) { 
				wx.showToast({
					title: '工作开始时间不能大于结束时间',
					icon:"none"
				})
				return false;
			}
		}
		// 判断 工作开始时间需大于  结束时间
		if (this.data.factoryJob.payType == '时' || this.data.factoryJob.payType == '小时') { 
			let start = '2022/10/11 ' + this.data.factoryJob.startTime;
			let end = '2022/10/11 ' + this.data.factoryJob.leaveTime;
			if (new Date(start).getTime() > new Date(end).getTime()) { 
				wx.showToast({
					title: '工作开始时间不能大于结束时间',
					icon:"none"
				})
				return false;
			}
		}
		this.setData({
			step: 2
		})
		wx.pageScrollTo({
			scrollTop: 0
		})
	},
	getFloatSalary() {

		http.getFloatSalary({}, res => {
			this.data.floatSalaryData = res.data;
			this.setFloat()
		}, err => { })
	},
	setFloat() {
		let key = this.data.factoryJob.payType;
		let data = {
			...this.data.floatSalaryData
		};
		let playStatus = getApp().globalData.playStatus;
		// debugger
		switch (key) {
			case '小时':
				if (playStatus == 1) {
					this.setData({
						['factoryJob.floatSalary']: data.returnFeeHour / 100,
						minFloat: data.returnFeeHour,
						minFloat1: data.minHour
					})
				} else {
					this.setData({
						minFloat: data.returnFeeHour,
						minFloat1: data.minHour
					})
				}
				break;
			case '时':
				if (playStatus == 1) {
					this.setData({
						['factoryJob.floatSalary']: data.returnFeeHour / 100,
						minFloat: data.returnFeeHour,
						minFloat1: data.minHour
					})
				} else {
					this.setData({
						minFloat: data.returnFeeHour,
						minFloat1: data.minHour,
					})
				}
				break;
			case '天':
				if (playStatus == 1) {
					this.setData({
						['factoryJob.floatSalary']: data.returnFeeDay / 100,
						minFloat: data.returnFeeDay,
						minFloat1: data.minDay
					})
				} else {
					this.setData({
						minFloat: data.returnFeeDay,
						minFloat1: data.minDay
					})
				}
				break;
			case '日':
				if (playStatus == 1) {
					this.setData({
						['factoryJob.floatSalary']: data.returnFeeDay / 100,
						minFloat: data.returnFeeDay,
						minFloat1: data.minDay
					})
				} else {
					this.setData({
						minFloat: data.returnFeeDay,
						minFloat1: data.minDay
					})
				}
				break;
			case '月':
				if (playStatus == 1) {
					this.setData({
						['factoryJob.floatSalary']: data.returnFeeMonth / 100,
						minFloat: data.returnFeeMonth,
						minFloat1: data.minMonth
					})
				} else {
					this.setData({
						minFloat: data.returnFeeMonth,
						minFloat1: data.minMonth
					})
				}
				break;
			case '次':
				this.setData({
					minFloat: data.returnFeeUnit,
				})
				break;
		}
	},
	backStep() {
		this.setData({
			step: 1
		})
	},
	newSetData() {
		let params = JSON.parse(JSON.stringify(getApp().globalData.workInfo))
		let copyWorkInfo = JSON.parse(JSON.stringify(getApp().globalData.workInfo))
		params.registerTime = copyWorkInfo.registerTime.split(' ')[0]
		params.asOfTime = copyWorkInfo.asOfTime.split(' ')[0]
		params.startTime = copyWorkInfo.startTime.split(' ')[1]
		params.leaveTime = copyWorkInfo.leaveTime.split(' ')[1]
		params.startDate = copyWorkInfo.startTime.split(' ')[0]
		params.leaveDate = copyWorkInfo.leaveTime.split(' ')[0]
		params.basicSalary = copyWorkInfo.basicSalary / 100;
		params.fixedSalary = copyWorkInfo.fixedSalary / 100;
		// if (copyWorkInfo.postType == 2) {
		params.floatSalary = copyWorkInfo.floatSalary / 100;
		// }
		if (params.payType.indexOf('时') > -1) {
			params.payType = "小时"
		}
		if (params.payType.indexOf('日') > -1) {
			params.payType = "天"
		}
		let pageTitle = "";
		if (params.postType == 1) {
			if (params.payType == '小时') {
				pageTitle = "兼职-时单"
			}
			if (params.payType == '天') {
				pageTitle = "兼职-日单"
			}
			if (params.payType == '次') {
				pageTitle = "兼职-次单"
			}
		} else {
			pageTitle = "全职"
		}
		wx.setNavigationBarTitle({
			title: pageTitle
		})
		if (copyWorkInfo.nationalLimited) {
			params.nations = copyWorkInfo.nationalLimited.split(',');
		} else {
			params.nations = []
		}
		params.workerPlace = copyWorkInfo.workPlace;
		let fileListImg = [];
		copyWorkInfo.image.split(',').map(item => {
			fileListImg.push({
				url: item,
				type: 'image',
				thumb: item
			})
		})
		this.setData({
			factoryJob: params,
			fileListImg
		})
	},
	saveLastSubmit(params) {
		let data = {
			sex: params.sex,
			education: params.education,
			minAge: params.minAge,
			maxAge: params.maxAge,
			nations: params.nations ? params.nations.split(',') : [],
			tattoo: params.tattoo,
			requirements: params.requirements,
			contactPerson: params.contactPerson,
			contactPhone: params.contactPhone,
		}
		wx.setStorageSync('lastData', data)
	},
	setLastData() {
		let data = wx.getStorageSync('lastData');
		if (!data) return;
		this.setData({
			['factoryJob.sex']: data.sex,
			['factoryJob.education']: data.education,
			['factoryJob.minAge']: data.minAge,
			['factoryJob.maxAge']: data.maxAge,
			['factoryJob.nations']: data.nations,
			['factoryJob.tattoo']: data.tattoo,
			['factoryJob.requirements']: data.requirements,
			['factoryJob.contactPerson']: data.contactPerson,
			['factoryJob.contactPhone']: data.contactPhone
		})
	},
	sbwy() {
		if (this.data.factoryJob.name) {
			wx.setStorageSync('lastData1', this.data.factoryJob)
		} else {
			wx.setStorageSync('lastData1', '')
		}
	},
})